<template>
  <view>
    <!-- 有商品页面-->
    <view v-if="cart.length">
      <!-- 地址框 -->
      <my-address></my-address>
      <view class="cart-title">
        <uni-icons type="shop" size="18"></uni-icons>
        <text>购物车</text>
      </view>
      <uni-swipe-action>
        <block v-for="(item,i) in cart" :key="i">
          <uni-swipe-action-item :rightOptions="options" @click="deleteGoods(item)">
            <my-goods :show-radio="true" :show-count="true" :goods="item" @radio-change="radioChange"
              @count-change="countChange"></my-goods>
          </uni-swipe-action-item>
        </block>
      </uni-swipe-action>
      <my-settle></my-settle>
    </view>
    <!-- 空页面-->
    <view class="empty-cart" v-else>
      <image src="../../static/cart_empty@2x.png" class="empty-img"></image>
      <text class="empty-text">空空如也~</text>
    </view>
  </view>
</template>

<script>
  import badge from '@/mixins/tabbar-badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#c00000'
          }
        }]
      };
    },
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'updateDeleteGoods']),
      radioChange(data) {
        this.updateGoodsState(data)
      },
      countChange(data) {
        this.updateGoodsCount(data)
      },
      deleteGoods(data) {
        this.updateDeleteGoods(data)
      }
    },
    //将分装的mixins混入到页面中使用
    mixins: [badge],

  }
</script>

<style lang="scss">
  .cart-title {
    height: 40px;
    display: flex;
    align-items: center;
    font-size: 14px;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;

    text {
      margin-left: 10px;
    }
  }

  .empty-cart {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 300rpx;

    .empty-img {
      width: 180rpx;
      height: 180rpx;
    }

    .empty-text {
      font-size: 24rpx;
      color: #808080;
      margin-top: 30rpx;
    }
  }
</style>
